<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrappe">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="领用人">
              <select-user-by-dep :multi="true" v-model="queryParam.cardRecipient"></select-user-by-dep>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="油卡卡号" style="height: 32px">
              <j-input placeholder="请输入油卡卡号" v-model="queryParam.cardNumberReal"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="车牌号" style="height: 32px">
              <j-input placeholder="请输入车牌号" v-model="queryParam.carNumber"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属月份">
              <!--              <a-range-picker-->
              <!--                :allowClear="false"-->
              <!--                v-model="createTime"-->
              <!--                style="width: 100%"-->
              <!--                @change="createTimeChange"/>  @change="createTimeChange"  @panelChange="handlePanelChange2"  -->
<!--              <a-range-picker-->
<!--                :allowClear="false"-->
<!--                :placeholder="['开始年月', '结束年月']"-->
<!--                format="YYYY-MM"-->
<!--                v-model="createTime"-->
<!--                :mode="mode2"-->
<!--                @change="handleChange"-->
<!--                @panelChange="handlePanelChange2"-->
<!--              />-->
              <a-month-picker @change="monthChange"  :disabled-date="disabledDate"  v-model="queryParam.targetTime" placeholder="所属月份" format="YYYY-MM" valueFormat="YYYY-MM" />
              <!--              <a-month-picker placeholder="开始年月" style="width: 100%" v-model="queryParam.createTime[0]" @change="onChange"/>-->
              <!--              ~-->
              <!--              <a-month-picker placeholder="结束年月" style="width: 100%" v-model="queryParam.createTime[1]" @change="onChange"/>-->
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('月份油卡及充值信息统计')" :disabled="isDisabledAuth('erpReportOilPay:export')">导出</a-button>
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style="iconStyle"/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <!---->
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:'180%'}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <a slot="oilBill" slot-scope="text, record" @click="getDetail(record.cardNumber)">{{ text }}</a>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a-button
            class="ruleButton"
            :ghost="true"
            type="primary"
            icon="edit"
            @click="handleEdit(record)"
            :disabled="isDisabledAuth('erpReportOilPay:edit')"
          />
          <a-divider type="vertical"/>
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a-button
              class="ruleButton"
              :ghost="true"
              type="primary"
              icon="delete"
              :disabled="isDisabledAuth('erpReportOilPay:delete')"/>
          </a-popconfirm>
        </span>
      </a-table>
    </div>
    <TravelReportModal ref="TravelReportModal"></TravelReportModal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import TravelReportModal from './components/TravelReportModal'
  import moment from 'moment';

  export default {
    name: 'ErpReportOilPayList',
    mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      SelectUserByDep,
      TravelReportModal
    },
    data () {
      return {
        description: '月份油卡及充值信息统计管理页面',
        // 表头
        columns: [],
        // 列设置
        settingColumns: [],
        // disabledDate: false,
        createTime: [moment().startOf('month').format('YYYY-MM-DD'), moment(moment().month(moment().month()).endOf('month').valueOf()).format('YYYY-MM-DD')],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '领用人',
            align: 'center',
            dataIndex: 'cardRecipient_dictText',
            width: 150,
            ellipsis: true
          },
          {
            title: '领用人薪级',
            align: 'center',
            dataIndex: 'payGradeId_dictText',
            width: 150,
            ellipsis: true
          },
          {
            title: '领用人职务',
            align: 'center',
            dataIndex: 'positionLevelId_dictText',
            width: 150,
            ellipsis: true
          },
          {
            title: '领用人所属团队',
            align: 'center',
            dataIndex: 'itemTeam',
            width: 180,
            ellipsis: true
          },
          {
            title: '固定车贴费用所属团队',
            align: 'center',
            dataIndex: 'belongTeam_dictText',
            width: 200,
            ellipsis: true
          },
          {
            title: '油卡卡号',
            align: 'center',
            dataIndex: 'cardNumber_dictText',
            scopedSlots: { customRender: 'oilBill' },
            width: 150,
            ellipsis: true
          },
          {
            title: '油卡所属公司',
            align: 'center',
            dataIndex: 'openCompany_dictText',
            width: 150,
            ellipsis: true
          },
          {
            title: '车牌号',
            align: 'center',
            dataIndex: 'carNumber',
            width: 150,
            ellipsis: true
          },
          // {
          //   title: '享受油补时间',
          //   align: 'center',
          //   dataIndex: 'oilSubsidyForceTime',
          //   width: 150,
          //   ellipsis: true,
          //   customRender: function (text) {
          //     return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          //   }
          // },
          // {
          //   title:'享受油补时间',
          //   align:"center",
          //   dataIndex: 'oilSubsidyForceTime',
          //   width: 150,
          //   ellipsis: true,
          //   customRender:function (text) {
          //     return !text?"":(text.length>10?text.substr(0,10):text)
          //   }
          // },
          {
            title: '固定车贴标准（元）',
            align: 'center',
            dataIndex: 'fixedSubsidy',
            width: 150,
            ellipsis: true
          },
          // {
          //   title:'公里数油补（元）',
          //   align:"center",
          //   dataIndex: 'reimbursableAmount',
          //   width: 150,
          //   ellipsis: true,
          // },
          {
            title: '本月出差公里数油补（元）',
            align: 'center',
            dataIndex: 'thisTraveledBusinessBalance',
            width: 150
          },
          {
            title: '本月油卡充值金额（元）',
            align: 'center',
            dataIndex: 'moneyTotal',
            width: 150,
            ellipsis: true
          },
          {
            title: '本月提现金额（元）',
            align: 'center',
            dataIndex: 'withdrawMoney',
            width: 150,
            ellipsis: true
          },
          {
            title: '出差公里数本月余额（元）',
            align: 'center',
            dataIndex: 'traveledBusinessBalance',
            width: 150,
            ellipsis: true
          },
          {
            title: '累计出差公里数补助（元）',
            align: 'center',
            dataIndex: 'reimbursableAmount',
            width: 150,
            customRender: (text, r) => {
              if (!text) {
                return ''
              } else {
                return <a v-on:click={(e) => this.onDetail(r)}>{text}</a>;
              }
            }
          }
        ],
        url: {
          list: '/api/erp/modules/workbench/report/erpReportOilPay/list',
          exportXlsUrl: '/api/erp/modules/workbench/report/erpReportOilPay/exportXls'
        },
        isorter: {
          column: '',
          order: ''
        },
        queryParam: {
          targetTime: moment().startOf('month').format("YYYY-MM")
          // beginDate: moment().startOf('month').format('YYYY-MM-DD'),
          // end: moment(moment().month(moment().month()).endOf('month').valueOf()).format('YYYY-MM-DD')
        },
        mode2: ['month', 'month'],
        value: [],
        dictOptions: {},
        superFieldList: []
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig() {
      },

      disabledDate(current) {
        // 获取当前日期
        const today = moment();

        // 获取当前年月
        const currentYear = today.year();
        const currentMonth = today.month() + 1;

        // 获取选择的年月
        const selectedYear = current.year();
        const selectedMonth = current.month() + 1;

        // 禁用还没到的日期选择
        return selectedYear > currentYear || (selectedYear === currentYear && selectedMonth > currentMonth);
      },
      // 查看详情
      getDetail(id) {
        this.$router.push({
          path: `/erp/workbench/oilSubsidy/oilSubsidyMaintain/ErpOilCardManagerListDetail/${id}`
        })
      },
      handleChange(value) {
        console.log('进入change方法：', value)
        this.createTime = value;
        this.$set(this.queryParam, 'beginDate', value[0])
        this.$set(this.queryParam, 'end', value[1])
        console.log('进入change方法：', this.queryParam)
      },
      monthChange(date,dateString){
        console.log(date)
        console.log(dateString)
        this.queryParam.targetTime = date
      },
      searchReset() {
        this.queryParam = {
          targetTime: moment().startOf('month').format("YYYY-MM")
        }
        // this.createTime = [moment().startOf('month').format('YYYY-MM-DD'), moment(moment().month(moment().month()).endOf('month').valueOf()).format('YYYY-MM-DD')]
        //console.log('传递的时间参数为：', this.targetTime)
        this.loadData(1)
      },
      customRow(record) {}, // 禁用双击详情
      getSuperFieldList() {
        let fieldList = [];
        fieldList.push({ type: 'string', value: 'cardRecipient', text: '领用人', dictCode: '' })
        fieldList.push({ type: 'string', value: 'payGradeId', text: '领用人薪级', dictCode: '' })
        fieldList.push({ type: 'string', value: 'positionLevelId', text: '领用人职务', dictCode: '' })
        fieldList.push({ type: 'string', value: 'itemTeam', text: '领用人所属团队', dictCode: '' })
        fieldList.push({ type: 'string', value: 'belongTeam', text: '固定车贴费用所属团队', dictCode: '' })
        fieldList.push({ type: 'string', value: 'cardNumber', text: '油卡卡号', dictCode: '' })
        fieldList.push({ type: 'string', value: 'openCompany', text: '油卡所属公司', dictCode: '' })
        fieldList.push({ type: 'string', value: 'carNumber', text: '车牌号', dictCode: '' })
        fieldList.push({ type: 'date', value: 'oilSubsidyForceTime', text: '享受油补时间' })
        fieldList.push({ type: 'BigDecimal', value: 'fixedSubsidy', text: '固定车贴标准', dictCode: '' })
        fieldList.push({ type: 'BigDecimal', value: 'reimbursableAmount', text: '公里数油补', dictCode: '' })
        fieldList.push({ type: 'BigDecimal', value: 'withdrawMoney', text: '提现金额', dictCode: '' })
        fieldList.push({ type: 'BigDecimal', value: 'traveledBusinessBalance', text: '出差公里数余额', dictCode: '' })
        this.superFieldList = fieldList
      },

      // 点击累计出差公里数补助
      onDetail (event) {
        // console.log('---', event)
        if (!event.cardRecipient) {
          return false
        }
        this.$refs.TravelReportModal.edit(event.cardRecipient)
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
